﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="notify_class_tree.aspx.cs" Inherits="Ccit.OA.Notify.notify_class_tree" %>
<%@ Register assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="Microsoft.Web.UI.WebControls" tagprefix="iewc" %>
<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
     <script language="javascript" src="../script/jquery.js" type="text/javascript"></script>
    <script language="javascript" src="../script/StringClass_Ext.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jsonlib.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jbase64.js" type="text/javascript"></script>
</head>
<body onclick="hideMenu()">
    <ccit:ActionForm id="form1" runat="server">
     <input type="hidden" id="_hidTabId" runat ="server" />
     <input type="hidden" id="_hidWhereClause" runat="server" />
   
    <input type="hidden" id="_hidUpAddrId" runat="server" />  
    <input type="hidden" id="_hidAddNewSign" runat="server" /> <!-- 新增记录标志 --> 
        <!--保存后传来的主键id-->
    <input type="hidden" id="_hidNewColumnId" runat="server" /> 
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server"></asp:ScriptManager>  
     <iewc:TreeView ID="trvDepAddress" runat="server">
    </iewc:TreeView>  
    <!--编辑页面保存成功的时候  调用的事件-->
    <input type="button" id="btnTrigger" onclick="doTrigger()" style="display:none" value="触发事件" />
    <!--编辑页面删除成功的时候  调用的事件-->
    <input type="button" id="btnDelTrigger" onclick="doDelTrigger()" style="display:none" value="删除触发事件" />
    <script type="text/javascript">
    <!--
        var menuskin = "skin";
		var node = null;
		var menuname = "root";	 
		 
		function hideMenu() 
		{		    
			var obj = document.getElementById(menuname);
			if (null != obj && typeof(obj) != "undefined")
				document.getElementById(menuname).style.visibility = "hidden";
		}
		
		function highlighItem() 
		{
			if (event.srcElement.className == "menuitems") 
			{
				event.srcElement.style.backgroundColor = "highlight";
				event.srcElement.style.color = "white";
			}
		}
		function lowlightItem() 
		{
			if (event.srcElement.className == "menuitems") 
			{
				event.srcElement.style.backgroundColor = "";
				event.srcElement.style.color = "black";
				window.status = "";
			}
		}
	 
		///节点展开
		function trvDepAddress.onexpand()
		{	
		    /* Step 1：find current click TreeNode */	    
		    var nodeIndex = event.treeNodeIndex;	
		    //alert(nodeIndex);		
			if (typeof(nodeIndex) == "undefined"){			
				node = null;
				return false;
			} 
			trvDepAddress.selectedNodeIndex = nodeIndex;
			node = trvDepAddress.getTreeNode(nodeIndex);
						
			/* Step 2: get asset type id，and get all child types */			
			var vNodeId = node.getAttribute("ID");
			var vNodeIdArray = vNodeId.split("_")
			var vAddressId = vNodeIdArray[0]; 
			
			if(vAddressId != "0") {
			    var oSubNodes = node.getChildren();
			    var oSubNode;
			    for(var i = oSubNodes.length - 1; i >= 0; i --) {
			        oSubNode = oSubNodes[i];
			        oSubNode.remove();
			    } 
			}
			hideMenu();
		}
		 
		///节点收缩
		function trvDepAddress.oncollapse()
		{
			hideMenu();
		}
		///更改节点属性值的时候
		function trvDepAddress.oncontextmenu()
		{				
			hideMenu();
			var nodeIndex = event.treeNodeIndex;							
			if (typeof(nodeIndex) == "undefined")
			{
				node = null;
				return false;
			}
			trvDepAddress.selectedNodeIndex = nodeIndex;
			node = trvDepAddress.getTreeNode(nodeIndex);			
			var vNodeId = node.getAttribute("ID");			
			var vNodeIdArray = vNodeId.split("_");
			var vAddressId = vNodeIdArray[0];
			　
			
			if(vAddressId == "0") return;  //根节点不显示右键菜单
			　
			var obj = document.getElementById("root");				
			if (null == obj || typeof(obj) == "undefined")
			{
				node = null;
				return false;
			}
			
			var rightedge = document.body.clientWidth - event.clientX;		//右边距
			var bottomedge = document.body.clientHeight - event.clientY;	//底边距
			
			if (rightedge < obj.offsetWidth)
				obj.style.left = document.body.scrollLeft + 5 + event.clientX - obj.offsetWidth;
			else
				obj.style.left = document.body.scrollLeft + 5 + event.clientX ;
			
			if (bottomedge < obj.offsetHeight)
				obj.style.top = document.body.scrollTop + 5 + event.clientY - obj.offsetHeight ;
			else
				obj.style.top = document.body.scrollTop + 5 + event.clientY ;
											
			obj.style.visibility = "visible";
			return false;
		}	
		 
		 
        //追加子节点
         
        ///查找节点
        function findTreeNode(findAstTypeId) {
            var ctrlTree = document.getElementById("trvDepAddress");		    
		    
		    var ctrlRoot = ctrlTree.getTreeNode("0"); 
		    var ctrlChildNodes = ctrlRoot.getChildren();
	    
		    var ctrlFindNode = recursionFind(ctrlChildNodes,findAstTypeId);
            return ctrlFindNode;

        }
        
        function recursionFind(ctrlChildNodes,findAddrId) {
            var iLen = ctrlChildNodes.length;
            var ctrlTreeNode;
		    var vNodeId;
		    var vNodeIdArray;
		    var vAddressId;
		    var ctrlSubChildNodes;
		    var bFind = false;
		    
            for(var i = 0; i < iLen; i ++) {
		        ctrlTreeNode = ctrlChildNodes[i];
		        vNodeId = ctrlTreeNode.getAttribute("ID");    
		        vNodeIdArray = vNodeId.split("_")
		        vAddressId = vNodeIdArray[0];
		        if(vAddressId == findAddrId) {		           
		            bFind = true;
		            break;       
		        }
		        else {
		            ctrlSubChildNodes = ctrlTreeNode.getChildren();
		            ctrlTreeNode = recursionFind(ctrlSubChildNodes,findAddrId);
		            if(null != ctrlTreeNode) {
		                bFind = true;
		                break;
		            } 
		        }
		    }
            
            if(bFind)
                return ctrlTreeNode;
            else
                return null;
        }
        //编辑页面保存成功的时候  调用的方法
        function doTrigger() {		    
		     doOperOriParentNode();  
		}
		//编辑页面删除成功的时候  调用的方法
		function doDelTrigger() {		     
		    var delAddrId = $get("_hidUpAddrId").value;
		    ctrlNode = findTreeNode(delAddrId);
		    nodeIndex = ctrlNode.getNodeIndex();
		    var node = $get("trvDepAddress").getTreeNode(nodeIndex); 
            node.remove();            
		}
		//找原父节点
		function doOperOriParentNode() { 
		    var isAddNew = $get("_hidAddNewSign").value;   //是否为编辑 1:编辑 
		    var curNodeExpr = $get("_hidNewColumnId").value;   //获取的是当前编辑的节点对象 eg:{"columnId":"26","columnName":"测试类型","hasChild":"1"}
		            eval("var curNodeObj=" + curNodeExpr);		           
		            var Name = curNodeObj.Name;
		            var ctrClickObj = findTreeNode(curNodeObj.Id);	 
		            //alert(colName);   
		    if(isAddNew=="1"){//编辑  
		            ctrClickObj.setAttribute("Text",Name);
		            return;  
		    }
		    else
		    {
		        var vDtNodeIndex = "0";
		        if(ctrClickObj!=null)		        
		        {
		            vDtNodeIndex = ctrClickObj.getNodeIndex();	
		        } 
		        createSubTNodes(vDtNodeIndex,curNodeObj);
		         var ctrlTree = document.getElementById("trvDepAddress");	
		         var ctrlRoot = ctrlTree.getTreeNode("0");
		         var ctrlDtNode = ctrlRoot;	
		         ctrlDtNode.setAttribute("EXPANDED",true);
		    }
		    DoSelIndex(curNodeObj);
		    return;		    
		}
		function DoSelIndex(curNodeObj)
		{
		  var nodes = new Array();
          var node=trvDepAddress.getTreeNode("0");   
          nodes = node.getChildren(); 
          for (var i = 0; i < nodes.length; i++) {
               var cNode=nodes[i]; 
               var checkNodeId=cNode.getAttribute("ID");
               if(curNodeObj.groupId==checkNodeId)
               {
                   var nodeIndex = cNode.getNodeIndex();
                   trvDepAddress.selectedNodeIndex = nodeIndex; 
                   break;
               }
            } 
		}
		 //追加子节点
        function createSubTNodes(nodeIndex,oResult) { 
			     var node = $get("trvDepAddress").getTreeNode(nodeIndex);  
			     var vPageParam = "NotiID="+oResult.Id;
                 var encodeParam = base64encode(vPageParam);
                 vNavigateUrl = "notify_class_edit.aspx?" + encodeParam;
                 oSubNode = $get("trvDepAddress").createTreeNode();
		         oSubNode.setAttribute("ID",oResult.Id);
		         oSubNode.setAttribute("Text",oResult.Name);
		         oSubNode.setAttribute("Type","root");
		         oSubNode.setAttribute("Target","iFrmEdit");
		         oSubNode.setAttribute("ImageUrl","../images/toolbar/filelogo.gif");
		         oSubNode.setAttribute("NavigateUrl",vNavigateUrl); 
		         node.add(oSubNode); 
        }   
		function initialTreeNode(ctrlFindNode) {
		    var ctrlTree = document.getElementById("trvDepAddress");	
		    var vNodeId;
		    var vNodeIdArray;
		    var vAddrId;	
		    var vNodeIndex;
		    var vNodeState;
		    if(null != ctrlFindNode) {
		        vNodeId = ctrlFindNode.getAttribute("ID");    
		        vNodeIdArray = vNodeId.split("_");
		        vAddrId = vNodeIdArray[0]; 
		        ctrlFindNode.setAttribute("ID",vAddrId);
		        vNodeIndex = ctrlFindNode.getNodeIndex();
		        ctrlTree.selectedNodeIndex = vNodeIndex;
		        /* 如果当前节点没有下级节点，则不会触发expand事件,
		         * 此时需要在当前节点下增加一个空节点 */
		        var vChildNodes = ctrlFindNode.getChildren();
		        if(vChildNodes.length == 0) {u
		           var oEmptyNode = $get("trvDepAddress").createTreeNode();  
		           ctrlFindNode.add(oEmptyNode);
		        }
		        ctrlFindNode.setAttribute("EXPANDED",true);
		    }
		}
		 
    //-->
    </script>
    
    </ccit:ActionForm>
</body>
</html>
